package org.yn.car.controller;

import org.yn.car.service.ICarOperateLogService;
import org.yn.car.domain.CarOperateLog;
import org.yn.car.query.CarOperateLogQuery;
import org.yn.base.util.AjaxResult;
import org.yn.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.yn.auth.annotation.PermissionAnnotation;
import java.util.List;

@PermissionAnnotation(name="carOperateLog管理",descs = "carOperateLog管理")
@Api("carOperateLog管理接口")
@RestController
@RequestMapping("/carOperateLog")
public class CarOperateLogController {
    @Autowired
    public ICarOperateLogService carOperateLogService;


    /**
     * 保存和修改公用的
     * @param carOperateLog 传递的实体
     * @return Ajaxresult转换结果
     */
    @PermissionAnnotation(name = "保存和修改CarOperateLog", descs = "保存和修改CarOperateLog")
    @ApiOperation(value = "保存和修改")
    @PostMapping
    public AjaxResult updateOrInsert(@RequestBody CarOperateLog carOperateLog) {
        if ( carOperateLog.getId() != null)
            carOperateLogService.update(carOperateLog);
            else
            carOperateLogService.insert(carOperateLog);
        return AjaxResult.success();
    }

    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @PermissionAnnotation(name = "删除CarOperateLog", descs = "删除CarOperateLog")
    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
            carOperateLogService.delete(id);
        return AjaxResult.success();
    }

    //获取用户
    @PermissionAnnotation(name = "获取单个CarOperateLog", descs = "获取单个CarOperateLog")
    @ApiOperation(value = "获取单个CarOperateLog")
    @GetMapping("/{id}")
    public AjaxResult selectById(@PathVariable("id") Long id) {
        CarOperateLog carOperateLog =carOperateLogService.selectById(id);
        return AjaxResult.success(carOperateLog);
    }


    /**
    * 查看所有的XX信息
    * @return
    */
    @PermissionAnnotation(name = "获取所有CarOperateLog", descs = "获取所有CarOperateLog")
    @ApiOperation(value = "获取所有CarOperateLog")
    @GetMapping
    public AjaxResult selectAll() {

        List< CarOperateLog> list = carOperateLogService.selectAll();
        return AjaxResult.success(list);
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageInfo 分页对象
    */
    @PermissionAnnotation(name = "分页查询CarOperateLog", descs = "分页查询CarOperateLog")
    @ApiOperation(value = "分页查询CarOperateLog")
    @PutMapping
    public AjaxResult queryPage(@RequestBody CarOperateLogQuery query) {
        PageInfo<CarOperateLog> pageInfo = carOperateLogService.queryPage(query);
        return AjaxResult.success(pageInfo);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PermissionAnnotation(name = "批量删除CarOperateLog", descs = "批量删除CarOperateLog")
    @ApiOperation(value = "批量删除CarOperateLog")
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
            carOperateLogService.batchDelete(ids);
        return AjaxResult.success();
    }
}